/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UserInterface.java
 *
 * Created on Feb 17, 2011, 1:07:29 PM
 */

package Project2.cs342.project1.mathNotebook.gui;

import Project2.cs342.project1.mathNotebook.data.*;
import Project2.cs342.project1.mathNotebook.notebook.NotebookEntry;
import Project2.cs342.project1.mathNotebook.notebook.NotebookEntryListModel;
import Project2.cs342.project1.mathNotebook.notebook.SlopeTable;
import Project2.cs342.project1.mathNotebook.Database.*;

import java.awt.Desktop;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Enumeration;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;


import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.io.*;
/**
 * Advanced User Interface for displaying graphs of formula's finding tangents and manipulating expressions.
 *
 * @author butzem57
 */
public class UserInterface extends javax.swing.JFrame {
    /**
     * Serves as the model for the list of notebook entries displayed to the user.
     */
    private List<NotebookEntry> notebookEntries;
    
    /**
     * View Model for the GUI's list of notebook entries
     */
    private NotebookEntryListModel notebookEntriesListModel;
    private SlopeTable slopeTable;
    private NotebookEntry ne;
    private String input;
    private String currentFilename;
    public static DBNotebooks notebooks;
    public static DBGroupAccess groupAccess;
    public static DBGroupMembers groupMember;
    public static DBGroups groups;
    public static DBUsers users;
    public String username;
    User user;




    
    /** Creates new form UserInterface
     */
    public UserInterface() {
    	this.notebookEntries = new ArrayList<NotebookEntry>();
        initComponents();
        
        
        
	localRadioButton.setSelected(true);
        //Makes all of the GUI items that deal with the cloud disabled
        fileDropdownBox.setEnabled(false);
        fileSelectionList.setEnabled(false);
   //     saveFileButton.setEnabled(false);
        downloadFileButton.setEnabled(false);
        uploadFileButton.setEnabled(false);
   //     lockUnlockButton.setEnabled(false);
        fileDropdownBox.setEnabled(false);
        groupOptionsMenu.setEnabled(false);
    }

    /** Creates new form UserInterface with User declared
     */
    public UserInterface(User user) {
    	this.notebookEntries = new ArrayList<NotebookEntry>();
        initComponents();

        this.user = user;

	localRadioButton.setSelected(true);
        //Makes all of the GUI items that deal with the cloud disabled
        fileDropdownBox.setEnabled(false);
        fileSelectionList.setEnabled(false);
        downloadFileButton.setEnabled(false);
        uploadFileButton.setEnabled(false);
        fileDropdownBox.setEnabled(false);
        groupOptionsMenu.setEnabled(false);
    }

    /**
     * Sets the current User.
     *
     * @param User object
     */
    public void setUser(User user){
        this.user = user;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        groupManagementFrame = new javax.swing.JFrame();
        groupSelectionComboBox = new javax.swing.JComboBox();
        groupNameLabel = new javax.swing.JLabel();
        addUserButton = new javax.swing.JButton();
        removeUserButton = new javax.swing.JButton();
        editAccessLevelButton = new javax.swing.JButton();
        disbandGroupButton = new javax.swing.JButton();
        scrolly = new javax.swing.JScrollPane();
        groupMembersList = new javax.swing.JList();
        loginFrame = new javax.swing.JFrame();
        usernameLabel = new javax.swing.JLabel();
        passwordLabel = new javax.swing.JLabel();
        usernameTextField = new javax.swing.JTextField();
        passwordTextField = new javax.swing.JPasswordField();
        addUserToGroupFrame = new javax.swing.JFrame();
        jPanel1 = new javax.swing.JPanel();
        readRadioButton = new javax.swing.JRadioButton();
        adminRadioButton = new javax.swing.JRadioButton();
        writeRadioButton = new javax.swing.JRadioButton();
        userComboBox = new javax.swing.JComboBox();
        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        accessLevelButtonGroup = new javax.swing.ButtonGroup();
        modeButtonGroup = new javax.swing.ButtonGroup();
        newGroupFrame = new javax.swing.JFrame();
        newGroupNameLabel = new javax.swing.JLabel();
        newGroupTextField = new javax.swing.JTextField();
        newGroupOkButton = new javax.swing.JButton();
        newGroupCancelButton = new javax.swing.JButton();
        editAccessLevelFrame = new javax.swing.JFrame();
        accessPanel = new javax.swing.JPanel();
        readRadioButton2 = new javax.swing.JRadioButton();
        adminRadioButton2 = new javax.swing.JRadioButton();
        writeRadioButton2 = new javax.swing.JRadioButton();
        okButton1 = new javax.swing.JButton();
        cancelButton1 = new javax.swing.JButton();
        editUserLabel = new javax.swing.JLabel();
        confirmDisbandGroupButton = new javax.swing.JFrame();
        jToggleButton1 = new javax.swing.JToggleButton();
        jToggleButton2 = new javax.swing.JToggleButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        accessLevelButtonGroup2 = new javax.swing.ButtonGroup();
        listPnl = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        notebookEntryJList = new javax.swing.JList();
        newExpBtn = new javax.swing.JButton();
        removeExpBtn = new javax.swing.JButton();
        viewPnl = new javax.swing.JPanel();
        formulaLbl = new javax.swing.JLabel();
        formulaTxt = new javax.swing.JTextField();
        minXLbl = new javax.swing.JLabel();
        lblDimensions = new javax.swing.JLabel();
        maxXLbl = new javax.swing.JLabel();
        minYLbl = new javax.swing.JLabel();
        maxYLbl = new javax.swing.JLabel();
        minXTxt = new javax.swing.JTextField();
        minYTxt = new javax.swing.JTextField();
        maxYTxt = new javax.swing.JTextField();
        maxXTxt = new javax.swing.JTextField();
        areaLbl = new javax.swing.JLabel();
        areaTxt = new javax.swing.JLabel();
        tangentLbl = new javax.swing.JLabel();
        slopeSbr = new javax.swing.JScrollPane();
        slopeTbl = new javax.swing.JTable();
        slopeBtn = new javax.swing.JButton();
        graphMaxY = new javax.swing.JLabel();
        graphMinY = new javax.swing.JLabel();
        graphMinX = new javax.swing.JLabel();
        graphMaxX = new javax.swing.JLabel();
        drawBtn = new javax.swing.JButton();
        removeSlopeBtn = new javax.swing.JButton();
        localRadioButton = new javax.swing.JRadioButton();
        cloudRadioButton = new javax.swing.JRadioButton();
        fileDropdownBox = new javax.swing.JComboBox();
        downloadFileButton = new javax.swing.JButton();
        uploadFileButton = new javax.swing.JButton();
        graph1 = new Project2.cs342.project1.mathNotebook.gui.Graph();
        jScrollPane1 = new javax.swing.JScrollPane();
        fileSelectionList = new javax.swing.JList();
        uploadFileButton1 = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newMenuItem = new javax.swing.JMenuItem();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        groupOptionsMenu = new javax.swing.JMenu();
        addGroupMenuItem = new javax.swing.JMenuItem();
        addNewFileToGroupMenuItem = new javax.swing.JMenuItem();
        groupManagerMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        groupManagementFrame.setAlwaysOnTop(true);
        groupManagementFrame.setMinimumSize(new java.awt.Dimension(558, 426));
        groupManagementFrame.setResizable(false);

        groupMember = new DBGroupMembers();
        String[] str = groupMember.retrieveGroupsForUser(this.username);
        groupSelectionComboBox.setModel(new javax.swing.DefaultComboBoxModel(str));
        groupSelectionComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                groupSelectionComboBoxActionPerformed(evt);
            }
        });

        groupNameLabel.setText("Group Name");

        addUserButton.setText("Add User");
        addUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addUserButtonActionPerformed(evt);
            }
        });

        removeUserButton.setText("Remove User");
        removeUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeUserButtonActionPerformed(evt);
            }
        });

        editAccessLevelButton.setText("Edit Access Level");
        editAccessLevelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editAccessLevelButtonActionPerformed(evt);
            }
        });

        disbandGroupButton.setText("Disband Group");

        groupMember = new DBGroupMembers();
        final String[] strUsers = groupMember.addAccessLevel(groupMember.retrieveUsersInGroup((String)groupSelectionComboBox.getSelectedItem()),(String)groupSelectionComboBox.getSelectedItem());
        System.out.println(strUsers[0]);
        groupMembersList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = strUsers;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        scrolly.setViewportView(groupMembersList);

        javax.swing.GroupLayout groupManagementFrameLayout = new javax.swing.GroupLayout(groupManagementFrame.getContentPane());
        groupManagementFrame.getContentPane().setLayout(groupManagementFrameLayout);
        groupManagementFrameLayout.setHorizontalGroup(
            groupManagementFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(groupManagementFrameLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(groupManagementFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(scrolly, javax.swing.GroupLayout.PREFERRED_SIZE, 424, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(groupManagementFrameLayout.createSequentialGroup()
                        .addComponent(addUserButton)
                        .addGap(18, 18, 18)
                        .addComponent(removeUserButton)
                        .addGap(18, 18, 18)
                        .addComponent(editAccessLevelButton)
                        .addGap(18, 18, 18)
                        .addComponent(disbandGroupButton))
                    .addGroup(groupManagementFrameLayout.createSequentialGroup()
                        .addComponent(groupNameLabel)
                        .addGap(18, 18, 18)
                        .addComponent(groupSelectionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(31, 31, 31))
        );
        groupManagementFrameLayout.setVerticalGroup(
            groupManagementFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(groupManagementFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(groupManagementFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(groupNameLabel)
                    .addComponent(groupSelectionComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(scrolly, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addGroup(groupManagementFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addUserButton)
                    .addComponent(removeUserButton)
                    .addComponent(editAccessLevelButton)
                    .addComponent(disbandGroupButton))
                .addContainerGap(82, Short.MAX_VALUE))
        );

        loginFrame.setTitle("Login");
        loginFrame.setMinimumSize(new java.awt.Dimension(324, 138));
        loginFrame.setName("loginFrame"); // NOI18N
        loginFrame.setResizable(false);

        usernameLabel.setText("Username");
        loginFrame.getContentPane().add(usernameLabel, java.awt.BorderLayout.CENTER);

        passwordLabel.setText("Password");
        loginFrame.getContentPane().add(passwordLabel, java.awt.BorderLayout.PAGE_START);
        loginFrame.getContentPane().add(usernameTextField, java.awt.BorderLayout.PAGE_END);
        loginFrame.getContentPane().add(passwordTextField, java.awt.BorderLayout.LINE_END);

        addUserToGroupFrame.setMinimumSize(new java.awt.Dimension(192, 210));
        addUserToGroupFrame.setResizable(false);

        accessLevelButtonGroup.add(readRadioButton);
        readRadioButton.setText("Read Only");

        accessLevelButtonGroup.add(adminRadioButton);
        adminRadioButton.setText("Read/Write/Admin");

        accessLevelButtonGroup.add(writeRadioButton);
        writeRadioButton.setText("Read/Write");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(readRadioButton)
                    .addComponent(writeRadioButton)
                    .addComponent(adminRadioButton))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(readRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(writeRadioButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(adminRadioButton)
                .addContainerGap())
        );

        okButton.setText("Ok");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout addUserToGroupFrameLayout = new javax.swing.GroupLayout(addUserToGroupFrame.getContentPane());
        addUserToGroupFrame.getContentPane().setLayout(addUserToGroupFrameLayout);
        addUserToGroupFrameLayout.setHorizontalGroup(
            addUserToGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addUserToGroupFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(addUserToGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(addUserToGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, addUserToGroupFrameLayout.createSequentialGroup()
                            .addComponent(okButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(userComboBox, 0, 168, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        addUserToGroupFrameLayout.setVerticalGroup(
            addUserToGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addUserToGroupFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(userComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(addUserToGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton)
                    .addComponent(okButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        newGroupNameLabel.setText("Group Name");

        newGroupTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newGroupTextFieldActionPerformed(evt);
            }
        });

        newGroupOkButton.setText("Ok");
        newGroupOkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newGroupOkButtonActionPerformed(evt);
            }
        });

        newGroupCancelButton.setText("Cancel");
        newGroupCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newGroupCancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout newGroupFrameLayout = new javax.swing.GroupLayout(newGroupFrame.getContentPane());
        newGroupFrame.getContentPane().setLayout(newGroupFrameLayout);
        newGroupFrameLayout.setHorizontalGroup(
            newGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newGroupFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(newGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(newGroupOkButton, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(newGroupNameLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(newGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(newGroupCancelButton)
                    .addComponent(newGroupTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        newGroupFrameLayout.setVerticalGroup(
            newGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newGroupFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(newGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newGroupNameLabel)
                    .addComponent(newGroupTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(newGroupFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newGroupOkButton)
                    .addComponent(newGroupCancelButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        editAccessLevelFrame.setTitle("Edit Access Level");
        editAccessLevelFrame.setMinimumSize(new java.awt.Dimension(192, 210));
        editAccessLevelFrame.setResizable(false);

        accessLevelButtonGroup2.add(readRadioButton2);
        readRadioButton2.setText("Read Only");

        accessLevelButtonGroup2.add(adminRadioButton2);
        adminRadioButton2.setText("Read/Write/Admin");

        accessLevelButtonGroup2.add(writeRadioButton2);
        writeRadioButton2.setText("Read/Write");

        javax.swing.GroupLayout accessPanelLayout = new javax.swing.GroupLayout(accessPanel);
        accessPanel.setLayout(accessPanelLayout);
        accessPanelLayout.setHorizontalGroup(
            accessPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(accessPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(accessPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(readRadioButton2)
                    .addComponent(writeRadioButton2)
                    .addComponent(adminRadioButton2))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        accessPanelLayout.setVerticalGroup(
            accessPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(accessPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(readRadioButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(writeRadioButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(adminRadioButton2)
                .addContainerGap())
        );

        okButton1.setText("Ok");
        okButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButton1ActionPerformed(evt);
            }
        });

        cancelButton1.setText("Cancel");
        cancelButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButton1ActionPerformed(evt);
            }
        });

        editUserLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        editUserLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editUserLabel.setMinimumSize(new java.awt.Dimension(100, 25));
        editUserLabel.setPreferredSize(new java.awt.Dimension(100, 25));

        javax.swing.GroupLayout editAccessLevelFrameLayout = new javax.swing.GroupLayout(editAccessLevelFrame.getContentPane());
        editAccessLevelFrame.getContentPane().setLayout(editAccessLevelFrameLayout);
        editAccessLevelFrameLayout.setHorizontalGroup(
            editAccessLevelFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editAccessLevelFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(editAccessLevelFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(editAccessLevelFrameLayout.createSequentialGroup()
                        .addComponent(okButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(accessPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(editUserLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        editAccessLevelFrameLayout.setVerticalGroup(
            editAccessLevelFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editAccessLevelFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(editUserLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(accessPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(editAccessLevelFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelButton1)
                    .addComponent(okButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        confirmDisbandGroupButton.setTitle("Disband Group?");

        jToggleButton1.setText("Ok");

        jToggleButton2.setText("Cancel");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel3.setText("Disband Group?");

        jLabel4.setFont(new java.awt.Font("Tahoma", 2, 12));
        jLabel4.setText("This will delete group entirely");

        javax.swing.GroupLayout confirmDisbandGroupButtonLayout = new javax.swing.GroupLayout(confirmDisbandGroupButton.getContentPane());
        confirmDisbandGroupButton.getContentPane().setLayout(confirmDisbandGroupButtonLayout);
        confirmDisbandGroupButtonLayout.setHorizontalGroup(
            confirmDisbandGroupButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(confirmDisbandGroupButtonLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jToggleButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, confirmDisbandGroupButtonLayout.createSequentialGroup()
                .addContainerGap(41, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addGap(31, 31, 31))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, confirmDisbandGroupButtonLayout.createSequentialGroup()
                .addContainerGap(62, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addGap(61, 61, 61))
        );
        confirmDisbandGroupButtonLayout.setVerticalGroup(
            confirmDisbandGroupButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, confirmDisbandGroupButtonLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addGap(18, 18, 18)
                .addGroup(confirmDisbandGroupButtonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jToggleButton1)
                    .addComponent(jToggleButton2))
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Math Notebook - Alejandro, Mack, Jared");
        setResizable(false);

        notebookEntryJList.setMinimumSize(new java.awt.Dimension(123, 420));
        notebookEntryJList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                notebookEntryJListMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(notebookEntryJList);

        newExpBtn.setText("New Expression");
        newExpBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newExpBtnActionPerformed(evt);
            }
        });

        removeExpBtn.setText("Remove Expression");
        removeExpBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeExpBtnActionPerformed(evt);
            }
        });

        formulaLbl.setText("Formula:");

        formulaTxt.setEditable(false);

        minXLbl.setText("Min X");

        lblDimensions.setText("Graph Dimensions:");

        maxXLbl.setText("Max X");

        minYLbl.setText("Min Y");

        maxYLbl.setText("Max Y");

        areaLbl.setText("Area:");

        areaTxt.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        tangentLbl.setText("Tangents Calculations:");

        slopeTbl.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "X", "Slope"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        slopeSbr.setViewportView(slopeTbl);

        slopeBtn.setFont(new java.awt.Font("Dialog", 1, 10));
        slopeBtn.setText("New Slope");
        slopeBtn.setMaximumSize(new java.awt.Dimension(50, 23));
        slopeBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                slopeBtnActionPerformed(evt);
            }
        });

        graphMaxY.setText("5.0");

        graphMinY.setText("-5.0");

        graphMinX.setText("-5.0");

        graphMaxX.setText("5.0");

        drawBtn.setText("Draw");
        drawBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                drawBtnActionPerformed(evt);
            }
        });

        removeSlopeBtn.setFont(new java.awt.Font("Dialog", 1, 10));
        removeSlopeBtn.setText("Remove Slope");
        removeSlopeBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeSlopeBtnActionPerformed(evt);
            }
        });

        modeButtonGroup.add(localRadioButton);
        localRadioButton.setText("Local Mode");
        localRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                localRadioButtonActionPerformed(evt);
            }
        });

        modeButtonGroup.add(cloudRadioButton);
        cloudRadioButton.setText("Cloud Mode");
        cloudRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cloudRadioButtonActionPerformed(evt);
            }
        });

        fileDropdownBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));
        fileDropdownBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fileDropdownBoxActionPerformed(evt);
            }
        });

        downloadFileButton.setText("Download");
        downloadFileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downloadFileButtonActionPerformed(evt);
            }
        });

        uploadFileButton.setText("Upload");
        uploadFileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uploadFileButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout graph1Layout = new javax.swing.GroupLayout(graph1);
        graph1.setLayout(graph1Layout);
        graph1Layout.setHorizontalGroup(
            graph1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 475, Short.MAX_VALUE)
        );
        graph1Layout.setVerticalGroup(
            graph1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 212, Short.MAX_VALUE)
        );

        fileSelectionList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = {};
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(fileSelectionList);

        uploadFileButton1.setText("Delete");
        uploadFileButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                uploadFileButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout viewPnlLayout = new javax.swing.GroupLayout(viewPnl);
        viewPnl.setLayout(viewPnlLayout);
        viewPnlLayout.setHorizontalGroup(
            viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(viewPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(formulaLbl)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(viewPnlLayout.createSequentialGroup()
                        .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(viewPnlLayout.createSequentialGroup()
                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                        .addComponent(graphMaxY)
                                        .addGap(23, 23, 23))
                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                        .addComponent(graphMinY, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(graphMinX)
                                        .addGap(426, 426, 426)
                                        .addComponent(graphMaxX, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                        .addGap(2, 2, 2)
                                        .addComponent(graph1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(viewPnlLayout.createSequentialGroup()
                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                        .addComponent(lblDimensions)
                                        .addGap(107, 107, 107)
                                        .addComponent(tangentLbl))
                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                        .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(viewPnlLayout.createSequentialGroup()
                                                .addGap(12, 12, 12)
                                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(minXLbl)
                                                    .addComponent(minYLbl)))
                                            .addComponent(areaLbl))
                                        .addGap(18, 18, 18)
                                        .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(viewPnlLayout.createSequentialGroup()
                                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(minXTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(minYTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                                        .addComponent(maxXLbl)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(maxXTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                                        .addComponent(maxYLbl)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(maxYTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                            .addComponent(drawBtn)
                                            .addComponent(areaTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addComponent(slopeSbr, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(12, 12, 12)
                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(slopeBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(removeSlopeBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(uploadFileButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(uploadFileButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(viewPnlLayout.createSequentialGroup()
                                .addComponent(localRadioButton)
                                .addGap(18, 18, 18)
                                .addComponent(cloudRadioButton))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)
                            .addComponent(fileDropdownBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(downloadFileButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(31, 31, 31))
                    .addComponent(formulaTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        viewPnlLayout.setVerticalGroup(
            viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(viewPnlLayout.createSequentialGroup()
                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(formulaLbl)
                    .addComponent(formulaTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(viewPnlLayout.createSequentialGroup()
                        .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(localRadioButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cloudRadioButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fileDropdownBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(downloadFileButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(uploadFileButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(uploadFileButton1)
                        .addGap(30, 30, 30))
                    .addGroup(viewPnlLayout.createSequentialGroup()
                        .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, viewPnlLayout.createSequentialGroup()
                                .addComponent(graphMaxY)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(graphMinY))
                            .addComponent(graph1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(viewPnlLayout.createSequentialGroup()
                                .addComponent(graphMinX)
                                .addGap(71, 71, 71)
                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                        .addGap(6, 6, 6)
                                        .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(lblDimensions)
                                            .addComponent(tangentLbl))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(viewPnlLayout.createSequentialGroup()
                                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(minXLbl)
                                                    .addComponent(maxXLbl)
                                                    .addComponent(minXTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(maxXTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(minYLbl)
                                                    .addComponent(maxYLbl)
                                                    .addComponent(maxYTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(minYTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(viewPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(areaLbl)
                                                    .addComponent(areaTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(15, 15, 15)
                                                .addComponent(drawBtn))
                                            .addComponent(slopeSbr, 0, 0, Short.MAX_VALUE)))
                                    .addGroup(viewPnlLayout.createSequentialGroup()
                                        .addGap(24, 24, 24)
                                        .addComponent(slopeBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(removeSlopeBtn))))
                            .addComponent(graphMaxX, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(43, 43, 43))
        );

        javax.swing.GroupLayout listPnlLayout = new javax.swing.GroupLayout(listPnl);
        listPnl.setLayout(listPnlLayout);
        listPnlLayout.setHorizontalGroup(
            listPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(listPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(listPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(removeExpBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(newExpBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(viewPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        listPnlLayout.setVerticalGroup(
            listPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(listPnlLayout.createSequentialGroup()
                .addGroup(listPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(listPnlLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(newExpBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 447, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(removeExpBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
                    .addGroup(listPnlLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(viewPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        fileMenu.setText("File");

        newMenuItem.setText("New");
        newMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(newMenuItem);

        openMenuItem.setText("Open");
        openMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(openMenuItem);

        saveMenuItem.setText("Save");
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setText("Save As ...");
        saveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveAsMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(saveAsMenuItem);

        exitMenuItem.setText("Exit");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        groupOptionsMenu.setText("Group Options");

        addGroupMenuItem.setText("Add Group");
        groupOptionsMenu.add(addGroupMenuItem);

        addNewFileToGroupMenuItem.setText("Add New File to Current Group");
        groupOptionsMenu.add(addNewFileToGroupMenuItem);

        groupManagerMenuItem.setText("Group Manager Menu");
        groupManagerMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                groupManagerMenuItemActionPerformed(evt);
            }
        });
        groupOptionsMenu.add(groupManagerMenuItem);

        menuBar.add(groupOptionsMenu);

        helpMenu.setText("Help");

        aboutMenuItem.setText("About");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(listPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(listPnl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /*
     * Closes form.
     */
    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed
    
    /*
     * Calculates slope at a particular x value and fills table with slope
     * 
     * @Author Mack Butzen
     * 
     * @param x value (from InputDialog)
     */
    private void slopeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_slopeBtnActionPerformed

        try {
            Double xCord;
            String slope = JOptionPane.showInputDialog("Please enter an 'x' value");
            xCord = Double.parseDouble(slope);

            //For testing purposes.  Shows result of slope calculation.
//            JOptionPane.showMessageDialog(
//                null, roundTwoDecimals(
//                    NotebookEntry.findSlopeAt(
//                        ne.function, Double.parseDouble(slope))));


            ne.tangentPoints.add(xCord);
            
            slopeTable = new SlopeTable(ne);
            slopeTbl.setModel(slopeTable);
            slopeTbl.getColumnModel().getColumn(0).setHeaderValue("X");
            slopeTbl.getColumnModel().getColumn(1).setHeaderValue("Slope");
            slopeTbl.repaint();
            graph1.drawGraph(ne);
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null,"Slope not valid");
        }
    }//GEN-LAST:event_slopeBtnActionPerformed

    /*
     * Takes a new expression, draws the expression on graph and adds expression to expression list.
     * 
     *  @Author Mack Butzen
     *  
     *  @param espression (from InputDialog)
     */
    private void newExpBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newExpBtnActionPerformed
    try{    
    	ne = new NotebookEntry();
        input = JOptionPane.showInputDialog(null, "Please enter an expression");

        Parser p = new  Parser();
        
        ne.function = p.getExpression(input);
    
        ne.minXCoordinate = -5.0;
        ne.maxXCoordinate = 5.0;
        ne.minYCoordinate = -5.0;
        ne.maxYCoordinate = 5.0;
        ne.functionString = input;

        //set graph hash marks
        graphMinX.setText(ne.minXCoordinate + "");
        graphMaxX.setText(ne.maxXCoordinate + "");
        graphMinY.setText(ne.minYCoordinate + "");
        graphMaxY.setText(ne.maxYCoordinate + "");

        //set graph size text boxes
        minXTxt.setText(ne.minXCoordinate + "");
        maxXTxt.setText(ne.maxXCoordinate + "");
        minYTxt.setText(ne.minYCoordinate + "");
        maxYTxt.setText(ne.maxYCoordinate + "");

        //ne.function = p.getExpression(input);

        notebookEntries.add(ne);
        
        formulaTxt.setText(input);
        graph1.drawGraph(ne);
        
        slopeTable = new SlopeTable(ne);
        slopeTbl.setModel(slopeTable);
        slopeTbl.repaint();

        //Get area
        //areaTxt.setText(ne.calculateArea() + "");
        areaTxt.setText(roundTwoDecimals(ne.calculateArea()) + "");
        
        notebookEntriesListModel = new NotebookEntryListModel(notebookEntries);
        notebookEntryJList.setModel(notebookEntriesListModel);
        notebookEntryJList.repaint();
        
        notebookEntryJList.setSelectedIndex(notebookEntries.size()-1);
        notebookEntryJList.repaint();
        
    }catch(Exception e){
    	JOptionPane.showMessageDialog(null,"Expression not valid");
    }
    }//GEN-LAST:event_newExpBtnActionPerformed

    private double roundTwoDecimals(double d) {
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        if ( new Double(d).toString().equals("NaN"))
        	return d;
        return Double.valueOf(twoDForm.format(d));
    }

    /*
     * When an expression is selected in the ExpressionList, load the expression as the current exp.
     * 
     * @Author Mack Butzen
     */
    private void notebookEntryJListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_notebookEntryJListMouseClicked
       if(this.notebookEntries.size() == 0) {
    	   return;
       }
    	
    	formulaTxt.setText(((NotebookEntry)(notebookEntryJList.getSelectedValue())).functionString);
        ne = (NotebookEntry)(notebookEntryJList.getSelectedValue());
        
        ne.minXCoordinate = -5.0;
        ne.maxXCoordinate = 5.0;
        ne.minYCoordinate = -5.0;
        ne.maxYCoordinate = 5.0;
        
      //set graph hash marks
        graphMinX.setText(ne.minXCoordinate + "");
        graphMaxX.setText(ne.maxXCoordinate + "");
        graphMinY.setText(ne.minYCoordinate + "");
        graphMaxY.setText(ne.maxYCoordinate + "");

        //set graph size text boxes
        minXTxt.setText(ne.minXCoordinate + "");
        maxXTxt.setText(ne.maxXCoordinate + "");
        minYTxt.setText(ne.minYCoordinate + "");
        maxYTxt.setText(ne.maxYCoordinate + "");
        
        areaTxt.setText(roundTwoDecimals(ne.calculateArea()) + "");
        
        graph1.drawGraph(ne);
        graph1.repaint();
        
        slopeTable = new SlopeTable((NotebookEntry)(notebookEntryJList.getSelectedValue()));
        slopeTbl.setModel(slopeTable);
        slopeTbl.getColumnModel().getColumn(0).setHeaderValue("X");
        slopeTbl.getColumnModel().getColumn(1).setHeaderValue("Slope");
        slopeTbl.repaint();
        
        
    }//GEN-LAST:event_notebookEntryJListMouseClicked
    
    /*
     * Redraws graph with new display parameters
     * 
     * @Author Mack Butzen
     */
    private void drawBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_drawBtnActionPerformed
        double minx, miny, maxx, maxy;

        try {

            minx = Double.parseDouble(minXTxt.getText());
            maxx = Double.parseDouble(maxXTxt.getText());
            miny = Double.parseDouble(minYTxt.getText());
            maxy = Double.parseDouble(maxYTxt.getText());

            if (minx > maxx || miny > maxy) {
                throw new Exception();
            }
            ne.minXCoordinate = Double.parseDouble(minXTxt.getText());
            ne.maxXCoordinate = Double.parseDouble(maxXTxt.getText());
            ne.minYCoordinate = Double.parseDouble(minYTxt.getText());
            ne.maxYCoordinate = Double.parseDouble(maxYTxt.getText());

            //set graph hash marks
            graphMinX.setText(ne.minXCoordinate + "");
            graphMaxX.setText(ne.maxXCoordinate + "");
            graphMinY.setText(ne.minYCoordinate + "");
            graphMaxY.setText(ne.maxYCoordinate + "");

        //recalculate area
        areaTxt.setText(roundTwoDecimals(ne.calculateArea()) + "");

        //redraw graph
        graph1.drawGraph(ne);
        
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null,"Graph bounds not valid");
        }
    }//GEN-LAST:event_drawBtnActionPerformed
    
    /**
     * Calls save as if the current notebook has not already saved. If it has
     * been saved before, simply save it to the current file.
     * @author Jared Schlicht
     * @param evt
     */
    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
    	if (this.currentFilename != null) {
    		this.saveFile();
    	} else {
    		this.saveFileAs();
    	}
    }//GEN-LAST:event_saveMenuItemActionPerformed
    
    /**
     * Creates a new notebook
     * @author Jared Schlicht
     * @param evt
     */
    private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMenuItemActionPerformed
    	this.notebookEntries.clear();
    	this.currentFilename = null;
    	this.notebookEntryJList.repaint();
    	this.areaTxt.setText("");
    	this.formulaTxt.setText("");
    	
    	this.graphMaxX.setText("");
    	this.maxXTxt.setText("");
    	
    	this.graphMaxY.setText("");
    	this.maxYTxt.setText("");
    	
    	this.graphMinX.setText("");
    	this.minXTxt.setText("");
    	
    	this.graphMinY.setText("");
    	this.minYTxt.setText("");
    	
    	this.ne = null;
    	this.graph1.drawGraph(this.ne);
    	
        slopeTbl.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null},
                    {null, null},
                    {null, null},
                    {null, null}
                },
                new String [] {
                    "X", "Slope"
                }
            ) {
                Class[] types = new Class [] {
                    java.lang.String.class, java.lang.String.class
                };

                public Class getColumnClass(int columnIndex) {
                    return types [columnIndex];
                }
            });
        slopeTbl.repaint();
    	
    	// this.slopeTable.slopeT.get(0).clear();
    	// this.slopeTable.slopeT.get(1).clear();
    	// this.slopeTable.entry = null;
    	// this.slopeTable.slopeT = new Double[0][0];
    }//GEN-LAST:event_newMenuItemActionPerformed
    
    /**
     * Opens ExpressionList from XML
     * 
     * @Author Mack Butzen
     */
    private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        
        int openResult = fileChooser.showOpenDialog(this);
        if (openResult != JFileChooser.APPROVE_OPTION) {
            return;
        }

        File file = fileChooser.getSelectedFile();
        this.currentFilename = file.getAbsolutePath();
        
        NotebookReader reader = new XMLNotebookRepositoryFactory(this.currentFilename).createReader();
        notebookEntries = reader.getAll();
        reader.close();
        notebookEntriesListModel = new NotebookEntryListModel(notebookEntries);
        notebookEntryJList.setModel(notebookEntriesListModel);
        notebookEntryJList.repaint();
        
        if(this.notebookEntries.size() == 0) {
     	   return;
        }
     	
        notebookEntryJList.setSelectedIndex(0);
        
     	formulaTxt.setText(((NotebookEntry)(notebookEntryJList.getSelectedValue())).functionString);
         ne = (NotebookEntry)(notebookEntryJList.getSelectedValue());

         ne.minXCoordinate = -5.0;
         ne.maxXCoordinate = 5.0;
         ne.minYCoordinate = -5.0;
         ne.maxYCoordinate = 5.0;
         
       //set graph hash marks
         graphMinX.setText(ne.minXCoordinate + "");
         graphMaxX.setText(ne.maxXCoordinate + "");
         graphMinY.setText(ne.minYCoordinate + "");
         graphMaxY.setText(ne.maxYCoordinate + "");

         //set graph size text boxes
         minXTxt.setText(ne.minXCoordinate + "");
         maxXTxt.setText(ne.maxXCoordinate + "");
         minYTxt.setText(ne.minYCoordinate + "");
         maxYTxt.setText(ne.maxYCoordinate + "");
         
         areaTxt.setText(roundTwoDecimals(ne.calculateArea()) + "");
         
         graph1.drawGraph(ne);
         graph1.repaint();
         
         slopeTable = new SlopeTable((NotebookEntry)(notebookEntryJList.getSelectedValue()));
         slopeTbl.setModel(slopeTable);
         slopeTbl.getColumnModel().getColumn(0).setHeaderValue("X");
         slopeTbl.getColumnModel().getColumn(1).setHeaderValue("Slope");
         slopeTbl.repaint();
    }//GEN-LAST:event_openMenuItemActionPerformed

    /**
     * Save current expression list to XML
     * @author Mack Butzen
     */
    private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuItemActionPerformed
    	this.saveFileAs();
    }//GEN-LAST:event_saveAsMenuItemActionPerformed

    /**
     * Shows the save as file dialog and writes the XML to the selected file
     * @author Jared Schlicht
     */
    private void saveFileAs() {
        JFileChooser fileChooser = new JFileChooser();

        int saveResult = fileChooser.showSaveDialog(this);
        if (saveResult != JFileChooser.APPROVE_OPTION) {
            return;
        }

        File file = fileChooser.getSelectedFile();
        this.currentFilename = file.getAbsolutePath();
        
        this.saveFile();
    }

    /**
     * Saves the current notebook entry to XML. The current filename must have
     * been set previously by the Save As method.
     * 
     * @author Jared Schlicht
     */
    private void saveFile() {
        NotebookWriter writer = new XMLNotebookRepositoryFactory(this.currentFilename).createWriter();
        writer.writeAll(notebookEntriesListModel.notebookEntries);
        writer.close();
    }
    
    /**
     * Removes expression from expression list
     * 
     * @param selected expression
     * @author Mack Butzen
     */
    private void removeExpBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeExpBtnActionPerformed

        try {
        //Reset graph view
        ne.minXCoordinate = -5.0;
        ne.maxXCoordinate = 5.0;
        ne.minYCoordinate = -5.0;
        ne.maxYCoordinate = 5.0;
        ne.functionString = input;

        //set graph hash marks
        graphMinX.setText(ne.minXCoordinate + "");
        graphMaxX.setText(ne.maxXCoordinate + "");
        graphMinY.setText(ne.minYCoordinate + "");
        graphMaxY.setText(ne.maxYCoordinate + "");

        //set graph size text boxes
        minXTxt.setText(ne.minXCoordinate + "");
        maxXTxt.setText(ne.maxXCoordinate + "");
        minYTxt.setText(ne.minYCoordinate + "");
        maxYTxt.setText(ne.maxYCoordinate + "");

        notebookEntriesListModel = new NotebookEntryListModel(notebookEntries);

        ne = new NotebookEntry();
        graph1.drawGraph(ne);
        areaTxt.setText("");
        formulaTxt.setText("");

        slopeTable = new SlopeTable(ne);
        slopeTbl.setModel(slopeTable);
        slopeTbl.getColumnModel().getColumn(0).setHeaderValue("X");
        slopeTbl.getColumnModel().getColumn(1).setHeaderValue("Slope");
        slopeTbl.repaint();

            int index = notebookEntryJList.getSelectedIndex();
            notebookEntries.remove(index);
            notebookEntryJList.setModel(notebookEntriesListModel);
            notebookEntryJList.repaint();
            graph1.repaint();
        }
        catch(Exception e) {}
    }//GEN-LAST:event_removeExpBtnActionPerformed

    private void removeSlopeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeSlopeBtnActionPerformed
        try {

            int index = notebookEntryJList.getSelectedIndex();
            notebookEntries.get(index).tangentPoints.remove(slopeTbl.getSelectedRow());
            slopeTable = new SlopeTable((NotebookEntry)(notebookEntryJList.getSelectedValue()));
            slopeTbl.setModel(slopeTable);
            slopeTbl.getColumnModel().getColumn(0).setHeaderValue("X");
            slopeTbl.getColumnModel().getColumn(1).setHeaderValue("Slope");
            slopeTbl.repaint();
            graph1.repaint();
        }
        catch(Exception e) {}
    }//GEN-LAST:event_removeSlopeBtnActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
    	File file = new File("docs/UserManual.pdf");
        try {
			Desktop.getDesktop().open(file);
		} catch (IOException e) {
		}
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void localRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_localRadioButtonActionPerformed
        //Makes all of the GUI items that deal with the cloud disabled
        fileDropdownBox.setEnabled(false);
        fileSelectionList.setEnabled(false);
     //   saveFileButton.setEnabled(false);
        downloadFileButton.setEnabled(false);
        uploadFileButton.setEnabled(false);
     //   lockUnlockButton.setEnabled(false);
        fileDropdownBox.setEnabled(false);
        groupOptionsMenu.setEnabled(false);
        

    }//GEN-LAST:event_localRadioButtonActionPerformed

    private void cloudRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cloudRadioButtonActionPerformed
        //Makes all of the GUI items that deal with the cloud enabled
        fileDropdownBox.setEnabled(true);
        fileSelectionList.setEnabled(true);
      //  saveFileButton.setEnabled(true);
        downloadFileButton.setEnabled(true);
        uploadFileButton.setEnabled(true);
      //  lockUnlockButton.setEnabled(true);
        fileDropdownBox.setEnabled(true);
        groupOptionsMenu.setEnabled(true);
        groupMember = new DBGroupMembers();
        String[] str = groupMember.retrieveGroupsForUser(this.username);
        fileDropdownBox.setModel(new javax.swing.DefaultComboBoxModel(str));
        groupAccess = new DBGroupAccess();
        fileSelectionList.setModel(new javax.swing.AbstractListModel() {

        String[] files = groupAccess.retrieveFilesForGroup((String)fileDropdownBox.getSelectedItem());
        String[] strings = files;
        public int getSize() { return strings.length; }
        public Object getElementAt(int i) { return strings[i]; }
});
    }//GEN-LAST:event_cloudRadioButtonActionPerformed

    private void fileDropdownBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileDropdownBoxActionPerformed
        // TODO add your handling code here:
        groupAccess = new DBGroupAccess();
        fileSelectionList.setModel(new javax.swing.AbstractListModel() {

        String[] files = groupAccess.retrieveFilesForGroup((String)fileDropdownBox.getSelectedItem());
    String[] strings = files;
    public int getSize() { return strings.length; }
    public Object getElementAt(int i) { return strings[i]; }
});
    }//GEN-LAST:event_fileDropdownBoxActionPerformed

    private void downloadFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadFileButtonActionPerformed
        NotebookZip zip = null;
	BigInteger desKey;
	LocalEncryptionWriter encryptedFile = null;
	DatabaseEncryptionReader dbEncryptWriter = null;
	zip = new NotebookZip();
        DBNotebooks dbNotebooks = new DBNotebooks();

        JFileChooser chooser = new JFileChooser();
        int returnValue = chooser.showSaveDialog(this);
        //returnValue == JFileChooser.APPROVE_OPTION
        if(true){
            String path = chooser.getSelectedFile().getAbsolutePath();//expecting user to create a file with a .encrypt extention it is 5 in the morning and I am going to bed
            String fileName = chooser.getSelectedFile().getName();
            System.out.println("Absolute Path: " + path);
            System.out.println("File Name: " + fileName);

            dbNotebooks.retrieveNotebooksContents(fileName, (String)fileSelectionList.getSelectedValue());
            
//            desKey = encryptedFile.getEncryptedSecretKey();
//            LocalEncryptionReader decryptedFile = new LocalEncryptionReader(user, desKey);
//            boolean readSuccess = decryptedFile.readEncryptedFile(fileName);
//            System.out.println("Encypted file downloaded "+readSuccess);
//            if(readSuccess){
//                zip.decompressFile(fileName.substring(0, fileName.length() - 8) + ".gzip");
//            }
            System.out.println("Finished with basic call");
        }else{
            System.out.println("Canceled by User");
        }
    }//GEN-LAST:event_downloadFileButtonActionPerformed

    

    private void uploadFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadFileButtonActionPerformed
        NotebookZip zip = null;
	BigInteger desKey;
	LocalEncryptionWriter encryptedFile = null;
	DatabaseEncryptionWriter dbEncryptWriter = null;
	zip = new NotebookZip();
        DBNotebooks dbNotebooks;

        JFileChooser chooser = new JFileChooser();
        String filename = null;
        int returnValue = chooser.showOpenDialog(this);
        if(returnValue == JFileChooser.APPROVE_OPTION){
            filename = chooser.getSelectedFile().getName();
            System.out.println("Attempting to Upload " + filename);
            zip.compressFile(filename);
            encryptedFile = new LocalEncryptionWriter(user, user.getDesDefaultKey());
            boolean writeSuccess = encryptedFile.writeEncryptedFile(getSubxml(filename) + ".gzip");
	    desKey = encryptedFile.getEncryptedSecretKey();
            if(writeSuccess){
                System.out.println("Able to writeout encrypted file = " + writeSuccess);
                dbNotebooks = new DBNotebooks();
                dbNotebooks.insertIntoNotebooks(getSubxml(filename) + ".encrypt", user.getUsername(), user.getRsaPublicKey(),
                                                user.getRsaPrivateKey(),desKey, (String)fileDropdownBox.getSelectedItem());
                        groupAccess = new DBGroupAccess();
                fileSelectionList.setModel(new javax.swing.AbstractListModel() {

                String[] files = groupAccess.retrieveFilesForGroup((String)fileDropdownBox.getSelectedItem());
            String[] strings = files;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });

            }

        }else{
            System.out.println("Canceled by User");
        }
    }//GEN-LAST:event_uploadFileButtonActionPerformed

    public String getDate(){
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        return sdf.format(cal.getTime());
    }

    private void groupSelectionComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupSelectionComboBoxActionPerformed

        groupMember = new DBGroupMembers();
        //final String[] strUsers2 = groupMember.retrieveUsersInGroup("Group 6");
        final String[] strUsers2 = groupMember.addAccessLevel(groupMember.retrieveUsersInGroup((String)groupSelectionComboBox.getSelectedItem()),(String)groupSelectionComboBox.getSelectedItem());
        groupMembersList.setModel(new javax.swing.AbstractListModel() {
        String[] strings = strUsers2;
        public int getSize() { return strings.length; }
        public Object getElementAt(int i) { return strings[i]; }
});
    }//GEN-LAST:event_groupSelectionComboBoxActionPerformed

    private void groupManagerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupManagerMenuItemActionPerformed
        groupMember = new DBGroupMembers();
        String[] str = groupMember.retrieveGroupsForUser(this.username);
        groupSelectionComboBox.setModel(new javax.swing.DefaultComboBoxModel(str));

        groupSelectionComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                groupSelectionComboBoxActionPerformed(evt);
            }
        });
        groupMember = new DBGroupMembers();
        //final String[] strUsers = groupMember.retrieveUsersInGroup((String)groupSelectionComboBox.getSelectedItem());
        final String[] strUsers = groupMember.addAccessLevel(groupMember.retrieveUsersInGroup((String)groupSelectionComboBox.getSelectedItem()),(String)groupSelectionComboBox.getSelectedItem());
        System.out.println(strUsers[0]);
        groupMembersList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = strUsers;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });


        groupManagementFrame.setVisible(true);
        
    }//GEN-LAST:event_groupManagerMenuItemActionPerformed

    private void addUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addUserButtonActionPerformed
    users = new DBUsers();
    final String[] strAllUsers = users.retrieveAllOtherUsers((String)groupSelectionComboBox.getSelectedItem());

    userComboBox.setModel(new javax.swing.DefaultComboBoxModel(strAllUsers));


            addUserToGroupFrame.setVisible(true);
    }//GEN-LAST:event_addUserButtonActionPerformed

    public static JRadioButton getSelection(ButtonGroup group) {
    for (Enumeration e=group.getElements(); e.hasMoreElements(); ) {
        JRadioButton b = (JRadioButton)e.nextElement();
        if (b.getModel() == group.getSelection()) {
            return b;
        }
    }
    return null;
}
    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        groupMember = new DBGroupMembers();
        groupMember.insertIntoGroupMembers((String)groupSelectionComboBox.getSelectedItem(), (String)userComboBox.getSelectedItem(),getSelection(accessLevelButtonGroup).getText() );
        final String[] strUsers = groupMember.retrieveUsersInGroup((String)groupSelectionComboBox.getSelectedItem());
        groupMembersList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = strUsers;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        accessLevelButtonGroup.clearSelection();
        addUserToGroupFrame.setVisible(false);
    }//GEN-LAST:event_okButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        // TODO add your handling code here:
        addUserToGroupFrame.setVisible(false);
        accessLevelButtonGroup.clearSelection();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void removeUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeUserButtonActionPerformed
        groupMember = new DBGroupMembers();
        String member = (String)groupMembersList.getSelectedValue();
        groupMember.deleteRowFromGroupMembers((String)groupSelectionComboBox.getSelectedItem(), member);
        groupMember = new DBGroupMembers();
        final String[] strUsers = groupMember.retrieveUsersInGroup((String)groupSelectionComboBox.getSelectedItem());
        System.out.println(strUsers[0]);
        groupMembersList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = strUsers;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        
        
    }//GEN-LAST:event_removeUserButtonActionPerformed

    private void newGroupTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newGroupTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_newGroupTextFieldActionPerformed

    private void newGroupOkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newGroupOkButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_newGroupOkButtonActionPerformed

    private void okButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButton1ActionPerformed
        editAccessLevelFrame.setVisible(false);
    }//GEN-LAST:event_okButton1ActionPerformed

    private void cancelButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButton1ActionPerformed
        editAccessLevelFrame.setVisible(false);
    }//GEN-LAST:event_cancelButton1ActionPerformed

    private void newGroupCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newGroupCancelButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_newGroupCancelButtonActionPerformed

    private void editAccessLevelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editAccessLevelButtonActionPerformed
        // TODO add your handling code here:
        String user = (String)groupMembersList.getSelectedValue();
//        editUserLabel.setText(user);
//        if (readRadioButton2.getText().equals(accessLevel))
//                readRadioButton2.setSelected(true);
//        if (writeRadioButton2.getText().equals(accessLevel))
//                writeRadioButton2.setSelected(true);
//        if (adminRadioButton2.getText().equals(accessLevel))
//                adminRadioButton2.setSelected(true);
        editAccessLevelFrame.setVisible(true);

    }//GEN-LAST:event_editAccessLevelButtonActionPerformed

    private void uploadFileButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadFileButton1ActionPerformed
        // TODO add your handling code here:
        notebooks = new DBNotebooks();
        notebooks.deleteNotebookFile((String)fileSelectionList.getSelectedValue());
        groupAccess = new DBGroupAccess();
        final String[] files = groupAccess.retrieveFilesForGroup((String)fileDropdownBox.getSelectedItem());
        fileSelectionList.setModel(new javax.swing.AbstractListModel() {

                
            String[] strings = files;
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
    }//GEN-LAST:event_uploadFileButton1ActionPerformed

    /**
     * used to remove the .xml extention
     *
     * @param str name of incoming file
     * @return filename without .xml
     */
    public String getSubxml(String str) {
        int tmp = str.length() - 4;
        System.out.println(str.substring(0, tmp) + ".xml");
        return str.substring(0, tmp);
    }

    /**
     *   used to remove the .gzip extention
     * @param str name of incoming file
     * @return filename without .gzip
     */
    public String getSubGZip(String str) {

        int tmp = str.length() - 5;
        System.out.println(str.substring(0, tmp) + ".gzip");
        return str.substring(0, tmp);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.ButtonGroup accessLevelButtonGroup;
    private javax.swing.ButtonGroup accessLevelButtonGroup2;
    private javax.swing.JPanel accessPanel;
    private javax.swing.JMenuItem addGroupMenuItem;
    private javax.swing.JMenuItem addNewFileToGroupMenuItem;
    private javax.swing.JButton addUserButton;
    private javax.swing.JFrame addUserToGroupFrame;
    private javax.swing.JRadioButton adminRadioButton;
    private javax.swing.JRadioButton adminRadioButton2;
    private javax.swing.JLabel areaLbl;
    private javax.swing.JLabel areaTxt;
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton cancelButton1;
    private javax.swing.JRadioButton cloudRadioButton;
    private javax.swing.JFrame confirmDisbandGroupButton;
    private javax.swing.JButton disbandGroupButton;
    private javax.swing.JButton downloadFileButton;
    private javax.swing.JButton drawBtn;
    private javax.swing.JButton editAccessLevelButton;
    private javax.swing.JFrame editAccessLevelFrame;
    private javax.swing.JLabel editUserLabel;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JComboBox fileDropdownBox;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JList fileSelectionList;
    private javax.swing.JLabel formulaLbl;
    private javax.swing.JTextField formulaTxt;
    private Project2.cs342.project1.mathNotebook.gui.Graph graph1;
    private javax.swing.JLabel graphMaxX;
    private javax.swing.JLabel graphMaxY;
    private javax.swing.JLabel graphMinX;
    private javax.swing.JLabel graphMinY;
    private javax.swing.JFrame groupManagementFrame;
    private javax.swing.JMenuItem groupManagerMenuItem;
    private javax.swing.JList groupMembersList;
    private javax.swing.JLabel groupNameLabel;
    private javax.swing.JMenu groupOptionsMenu;
    private javax.swing.JComboBox groupSelectionComboBox;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton jToggleButton2;
    private javax.swing.JLabel lblDimensions;
    private javax.swing.JPanel listPnl;
    private javax.swing.JRadioButton localRadioButton;
    private javax.swing.JFrame loginFrame;
    private javax.swing.JLabel maxXLbl;
    private javax.swing.JTextField maxXTxt;
    private javax.swing.JLabel maxYLbl;
    private javax.swing.JTextField maxYTxt;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JLabel minXLbl;
    private javax.swing.JTextField minXTxt;
    private javax.swing.JLabel minYLbl;
    private javax.swing.JTextField minYTxt;
    private javax.swing.ButtonGroup modeButtonGroup;
    private javax.swing.JButton newExpBtn;
    private javax.swing.JButton newGroupCancelButton;
    private javax.swing.JFrame newGroupFrame;
    private javax.swing.JLabel newGroupNameLabel;
    private javax.swing.JButton newGroupOkButton;
    private javax.swing.JTextField newGroupTextField;
    private javax.swing.JMenuItem newMenuItem;
    private javax.swing.JList notebookEntryJList;
    private javax.swing.JButton okButton;
    private javax.swing.JButton okButton1;
    private javax.swing.JMenuItem openMenuItem;
    private javax.swing.JLabel passwordLabel;
    private javax.swing.JPasswordField passwordTextField;
    private javax.swing.JRadioButton readRadioButton;
    private javax.swing.JRadioButton readRadioButton2;
    private javax.swing.JButton removeExpBtn;
    private javax.swing.JButton removeSlopeBtn;
    private javax.swing.JButton removeUserButton;
    private javax.swing.JMenuItem saveAsMenuItem;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JScrollPane scrolly;
    private javax.swing.JButton slopeBtn;
    private javax.swing.JScrollPane slopeSbr;
    private javax.swing.JTable slopeTbl;
    private javax.swing.JLabel tangentLbl;
    private javax.swing.JButton uploadFileButton;
    private javax.swing.JButton uploadFileButton1;
    private javax.swing.JComboBox userComboBox;
    private javax.swing.JLabel usernameLabel;
    private javax.swing.JTextField usernameTextField;
    private javax.swing.JPanel viewPnl;
    private javax.swing.JRadioButton writeRadioButton;
    private javax.swing.JRadioButton writeRadioButton2;
    // End of variables declaration//GEN-END:variables
    
}
